package com.stylefeng.guns.rest.modular.controller;

import com.stylefeng.guns.rest.emailserver.MailController;
import com.stylefeng.guns.rest.emailserver.MailServer;
import com.stylefeng.guns.rest.emailserver.QQEmailServer;
import com.stylefeng.guns.rest.pojo.EmailObject;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @author yuzih
 * @create 2018-05-25 11:22
 * @desc 邮件业务controller
 **/
@Controller
@RequestMapping("/email")
public class EmailController {

    @RequestMapping("/sendEmail")
    public ResponseEntity hello(@RequestBody EmailObject emailObject) {

        System.out.println(emailObject);

        MailServer mailServer = new QQEmailServer();
        ExecutorService fixedThreadPool = Executors.newFixedThreadPool(10);
        MailController mailController = MailController.init(mailServer, emailObject);

        fixedThreadPool.execute(mailController);
        return ResponseEntity.ok("请求成功!");
    }
}
